import axios from 'axios'
// 基准路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1'
// 请求拦截器
axios.interceptors.request.use(function (config) {
  // Do something before request is sent
  // console.log(config)
  // 取出存的token
  let mytoken = localStorage.getItem('mytoken') || ''
  // 判断token是否存在
  if (mytoken) {
    config.headers['Authorization'] = mytoken
  }
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})
// 获取商品分类数据
export const goodsification = (mun, obj) => axios.get('/categories', {params: {type: mun, pagenum: obj.currentPage, pagesize: obj.pagesize}}).then(res => res.data)
// 获取商品分类数据渲染在添加分类级联菜单中的
export const addgoodsInfo = num => axios.get('/categories', { params: { type: num } }).then(res => res.data)
// 添加分类
export const categories = obj => axios.post('/categories', obj).then(res => res.data)
